package day06;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import com.sun.org.apache.regexp.internal.RE;

import java.util.Arrays;
//求数组元素的最大值,并将最大值其绑在数组最后一个元素下的位置
public class MaxofArray {
    public static void main(String[] args) {
        /*
        int[] arr={3,5,7,34,54,25};
        int max=arr[0];
        for (int i=1;i<arr.length;i++){
            if (arr[i]>max){
                max=arr[i];
            }
        }
        System.out.println("最大值为："+max);

        int[] acc= {13,84,26,17,48,68,641,41,481};
        int mca=acc[0];
        for (int c=1;c>acc.length;c++){
            if (acc[c]<mca){
                mca=acc[c];
            }
        }
        System.out.println("最大值为："+mca);
         */
        /*int sum=0;
        for (int i=2;i<=100;i+=2){
            sum+=i;
        }
        System.out.println("sum="+sum);
        */
        /*int num=1;
        for (int i=1;i<=8;i++){
            num*=i;
        }
        System.out.println("num"+num);

         */
        /*
        for (int nn=1;nn<=11;nn+=2){
            for (int o=1;o<=nn;o++){
                System.out.print("*");
            }
            System.out.println();
        }
        for(int i=0;i<6;i++){
            for(int k=1;k<=2*i+1;k++){
                System.out.print("*");
            }
            System.out.println();
        }

        for (int i=1;i<=6;i++){
            System.out.println();
            for (int o=1;o<=11-i;o++){
                System.out.print(" ");
            }
            for (int k=1;k<=i*2-1;k++) {
                System.out.print("*");
            }

        }
        int[] a=new int[10];
        for (int p=0;p<a.length;p++){
            a[p]=(int)(Math.random()*100);
            System.out.println(a[p]);
        }
        int m=a[0];
        int n=a[0];
        for (int t=1;t<a.length;t++){
            if (a[t]>m){
                m=a[t];
            }else if (a[t]<n){
                n=a[t];
            }
        }
        System.out.println("最大值为："+m+"最小值为："+n);

        int z=0;
        for (int r=2;r<=100;r+=2){
            z=r;
        }
        System.out.println("z="+z);
        */
        /*
        int[] a=new int[10];
        for (int p=0;p<a.length;p++) {
            a[p] = (int) (Math.random() * 100);
            System.out.println(a[p]);
            int max = a[0];
            for (int i = 1; i < a.length; i++) {
                if (a[i] > max) {
                    max = a[i];
                }
            }
        }

        a=Arrays.copyOf(a, a.length+1);
        *//*
        int[] arr={23,36,74,84,2,4};
        int max = generateOfArray(arr);
        System.out.println(max);
        int[] asd =new int[10];
        for (int i=0;i<asd.length;i++){
            asd[i]=(int) (Math.random()*100);
        }
        int m=generateOfArray(asd);
        System.out.println(m);
        */
        /*
        int[]a={10,20,30,40,50};
        int[]b=new int[6];
        System.arraycopy(a,1,b,0,4);
        for (int i=0;i<b.length;i++){
            System.out.println(b[i]);
        }
         */
        /*
        int[]c={10,20,30,40,50};
        int[]d=Arrays.copyOf(c,4);
        for (int o=0;o<d.length;o++){
            System.out.println(d[o]);
        }*//*
        int[]a={10,20,30,40,50};
        a=Arrays.copyOf(a,a.length+1);
        for (int i=0;i<a.length;i++){
            System.out.println(a[i]);
        }
        int[]arr=new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i]=(int)(Math.random()*100);
            System.out.println(arr[i]);
        }
        int max=arr[0];
        for(int i=1;i<arr.length;i++){
            if (arr[i]>max){
                max=arr[i];
            }
        }
        System.out.println("最大值"+max);
        arr=Arrays.copyOf(arr,arr.length+1);
        arr[arr.length-1]=max;
        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }*//*
        int[] arr= new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i]=(int) (Math.random()*100);
            System.out.println(arr[i]);
        }
        int max=arr[0];
        for (int i=1;i<arr.length;i++){
            max=arr[i];
        }
        System.out.println(max);
        arr=Arrays.copyOf(arr,arr.length+1);
        arr[arr.length-1]=max;
        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }*/
        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i]=(int) (Math.random()*100);
            System.out.println(arr[i]);
        }
        int max=arr[0];
        for (int i=1;i<arr.length;i++){
            if (arr[i]>max){
                max = arr[i];
            }
            System.out.println("最大值"+max);
            arr = Arrays.copyOf(arr,arr.length+1);
            arr[arr.length-1] =max;
            for (int o=0;o<arr.length;o++){
                System.out.println(arr[o]);
            }
            int[] a = {100,20,30,40,50};
            int[] b = new int[6];
            System.arraycopy(a,1,b,0,4);
            for (int l=0;l<b.length;l++){
                System.out.println(b[l]);
            }

        }

        int[] ar ={23,36,74,84,2,4};
        int ma = getMax(ar);
        System.out.println(ma);
        int[]as=new int[10];
        for (int i=0;i<as.length;i++){
            as[i]=(int) (Math.random()*100);
        }
        int n=getMax(as);
        System.out.println(ma);




    }
    /*public static int generateOfArray(int[]arr){
        int max=arr[0];
        for (int i=1;i<arr.length;i++){
            if (arr[i]>max){
                max=arr[i];
            }
        }
        return max;
    }*/
    public static int getMax(int[]ar){
        int ma=ar[0];
        for (int i=1;i<ar.length;i++){
            if (ar[i]>ma){
                ma=ar[i];
            }
        }
        return ma;
    }



}
